package com.gp;

import java.util.List;

import com.stock.StockData;

// the fitness implementation
public class Fitness {

	// calc and set the chromosomes fitness
	public static void updateFit(List<Chrome> AllChrome, StockData buyDay, StockData sellDay) {
		double fromPrice = buyDay.getClosingPrice();
		double toPrice = sellDay.getClosingPrice();
		if(fromPrice != 0 && toPrice != 0){
			for (Chrome chrome : AllChrome) {				
				//double fit = Math.abs(chrome.getValue(buyDay) - (toPrice - fromPrice)); // -> 0 is better
				double fit = Math.abs(chrome.getValue(buyDay) - toPrice ); // -> 0 is better
				
				//double fit = chrome.getValue(buyDay) * ( (toPrice  /  fromPrice) - 1.0) * 100.0;  //  the chrome will return if to buy or not (+ -)
					//((closing price of current day/closing price N days ago)-1)*100
				if (Double.isNaN(fit) || Double.isInfinite(fit)){
					fit = 100;
				}
				
				chrome.setFit(fit);
			}
		}
	}
	
}
